#ifndef __RF_BIT_PROC_H
#define __RF_BIT_PROC_H

#include "gd32e10x.h"




#if  0
//采样时间 100us
#define MIN_ONE_BIT_DATA_GAP            7      //define min 1 bit gap
#define MAX_ONE_BIT_DATA_GAP            13     //define max 1 bit gap
#define MIN_ZERO_P_FIVE_BIT_DATA_GAP    3      //define min 0.5 bit gap
#define MAX_ZERO_P_FIVE_BIT_DATA_GAP    6      //define max 0.5 bit gap

#else

//采样时间 67us
#define MIN_ONE_BIT_DATA_GAP            12      //define min 1 bit gap    1000us
#define MAX_ONE_BIT_DATA_GAP            18     //define max 1 bit gap
#define MIN_ZERO_P_FIVE_BIT_DATA_GAP    5      //define min 0.5 bit gap   500us
#define MAX_ZERO_P_FIVE_BIT_DATA_GAP    10      //define max 0.5 bit gap
#endif

#define RF_MAX_LENGHT                   104       //高频数据最大长度


#define GET_BIT(data, bits)    (((data)>>(bits))&0x01)
#define SET_BIT(data, bits)    ((data) |= (0x01L<<(bits)))
#define CLR_BIT(data, bits)    ((data) &= (~(0x01L<<(bits))))

#define RF_NORMAL_RECV         0
#define RF_ABNORMAL_RECV       1


//位调试部分
#define debug_433_def   0
#if debug_433_def
#define defBufLen  8000
#endif


typedef struct {
	
	uint8_t  Back_state;            	 	//上一次
  uint8_t  Cur_state;              		//当前状态

  uint8_t  Back_Low_bits;            //上一次低电平位数
  uint8_t  Back_High_bits;           //上一次低电平位数
  uint8_t  Cur_Low_bits;             //当前低电平位数
  uint8_t  Cur_High_bits;            //当前高电平位数
  uint8_t  value;


}RF_BSP_TypeDef;



uint8_t RF_Recevie_Code(uint8_t curbit);
void RF_Recevie_Unit(uint8_t unit);
void RF_Stop_Rece_Code(uint8_t  Type);
void detect_key_result(void);


#endif
